/**********************************************************************************************************
** 驱动文件：	jmkt-HFIM4.c
** 驱动类型：	jmkt
** 设备名称：	基站空调
** 设备型号：	HFIM4
** 设备品牌：	海悟
** 设备协议：	电总协议
** 驱动描述：	适用于海悟新型基站专用空调,HFIM4控制器。
** 生成日期：	2019-10-27 15:07:20
**********************************************************************************************************/
#include "Includes.h"


/**********************************************************************************************************
* 定义设备数据点变量结构
**********************************************************************************************************/
typedef struct{
	Var APhaseVoltage;							//A相电压
	Var BPhaseVoltage;							//B相电压
	Var CPhaseVoltage;							//C相电压
	Var APhaseCurrent;							//A相电流
	Var BPhaseCurrent;							//B相电流
	Var CPhaseCurrent;							//C相电流
	Var DeliveryAirTemperature;					//送风温度
	Var DeliveryAirHumidity;					//送风湿度
	Var RoomTemperature;						//室内温度
	Var RoomHumidity;							//室内湿度
	Var OutdoorTemperature;						//室外温度
	Var OutdoorHumidity;						//室外湿度
	Var CompressorSuctionPressure;				//压缩机吸气压力
	Var CompressorExhaustPressure;				//压缩机排气压力
	Var CompressorExhaustTemperature;			//压缩机排气温度
	Var EvaporatorCoilTemperature;				//蒸发器盘管温度
	Var CompressorRunningTime;					//压缩机运行时间
	Var UnitRunningTime;						//机组运行时间
	Var OnOff;									//空调开/关状态
	Var AirConditioningMode;					//空调运行模式
	Var IndoorFanStatus;						//内风机状态
	Var FourWayValveStatus;						//四通阀状态
	Var CompressorStatus;						//压缩机状态
	Var OutdoorFanStatus;						//外风机状态
	Var WindyState;								//摆风状态
	Var ElectricHeatingState;					//电加热状态
	Var FilterCloggingAlarm;					//过滤器堵塞报警
	Var CompressorOverloadAlarm;				//压缩机过载报警
	Var IndoorFanOverloadAlarm;					//内风机过载报警
	Var SystemHighPressureAlarm;				//系统高压报警
	Var SystemLowPressureAlarm;					//系统低压报警
	Var ExhaustTemperatureAlarm;				//排气温度报警
	Var InternalExternalCommunicationFailure;	//内外机通讯故障
	Var RoomTemperatureSensor;					//室内环境温度传感器
	Var InnerCoilInletTemperatureSensor;		//内机盘管进口温度传感器
	Var InternalCoilMiddleTemperatureSensor;	//内机盘管中间温度传感器
	Var InnerCoilOutletTemperatureSensor;		//内机盘管出口温度传感器
	Var OutdoorTemperatureSensor;				//室外环境温度传感器
	Var ExternalCoilTemperatureSensor;			//外机盘管温度传感器
	Var ExhaustTemperatureSensor;				//排气温度传感器
	Var PhaseSequenceError;						//相序错误报警
	Var PhaseLossProtection;					//缺相报警
	Var OutdoorFanProtectionAlarm;				//室外风机保护报警
	Var EEPROMFailure;							//EEPROM故障
	Var SmokeAlarm;								//烟雾告警
	Var IndoorHumiditySensor;					//室内湿度传感器
	Var OutdoorHumiditySensor;					//室外湿度传感器
	Var SystemException;						//系统异常
	Var LeakageAlarm;							//水浸告警
	Var OtherAbnormalAlarms;					//其它不正常告警
	Var ExternalTheftAlarm;						//外机被盗告警
	Var CoolingModeTemperatureSetting;			//制冷模式温度设定值
	Var HeatingModeTemperatureSetting;			//制热模式温度设定值
}Data_Struct;									//定义变量结构


/**********************************************************************************************************
* 设备数据点变量属性声明
**********************************************************************************************************/
const static Var_Property_Def var_attr[] = {
	{
		INTEGER,
		0,
		READONLY,
		"APhaseVoltage",
		"A相电压",
		"V",
		"主机电源相压A",
		0,
		0,
		"主机电源相压A过高",
		"主机电源相压A过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"BPhaseVoltage",
		"B相电压",
		"V",
		"主机电源相压B",
		0,
		0,
		"主机电源相压B过高",
		"主机电源相压B过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"CPhaseVoltage",
		"C相电压",
		"V",
		"主机电源相压C",
		0,
		0,
		"主机电源相压C过高",
		"主机电源相压C过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"APhaseCurrent",
		"A相电流",
		"A",
		"主机/压缩机工作电流A相",
		0,
		0,
		"主机/压缩机工作电流A相过高",
		"主机/压缩机工作电流A相过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"BPhaseCurrent",
		"B相电流",
		"A",
		"主机/压缩机工作电流B相",
		0,
		0,
		"主机/压缩机工作电流B相过高",
		"主机/压缩机工作电流B相过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"CPhaseCurrent",
		"C相电流",
		"A",
		"主机/压缩机工作电流C相",
		0,
		0,
		"主机/压缩机工作电流C相过高",
		"主机/压缩机工作电流C相过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"DeliveryAirTemperature",
		"送风温度",
		"℃",
		"送风温度",
		0,
		0,
		"送风温度过高",
		"送风温度过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"DeliveryAirHumidity",
		"送风湿度",
		"%",
		"送风湿度",
		0,
		0,
		"送风湿度过高",
		"送风湿度过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"RoomTemperature",
		"室内温度",
		"℃",
		"回风温度/室内环境温度",
		0,
		0,
		"室内温度过高",
		"室内温度过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"RoomHumidity",
		"室内湿度",
		"%",
		"回风湿度/室内环境湿度",
		0,
		0,
		"室内湿度过高",
		"室内湿度过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"OutdoorTemperature",
		"室外温度",
		"℃",
		"室外环境温度",
		0,
		0,
		"室外温度过高",
		"室外温度过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"OutdoorHumidity",
		"室外湿度",
		"%",
		"室外环境湿度",
		0,
		0,
		"室外湿度过高",
		"室外湿度过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"CompressorSuctionPressure",
		"压缩机吸气压力",
		"Bar",
		"压缩机吸气压力",
		0,
		0,
		"压缩机吸气压力过高",
		"压缩机吸气压力过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"CompressorExhaustPressure",
		"压缩机排气压力",
		"Bar",
		"压缩机排气压力",
		0,
		0,
		"压缩机排气压力过高",
		"压缩机排气压力过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"CompressorExhaustTemperature",
		"压缩机排气温度",
		"℃",
		"压缩机排气温度",
		0,
		0,
		"压缩机排气温度过高",
		"压缩机排气温度过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"EvaporatorCoilTemperature",
		"蒸发器盘管温度",
		"℃",
		"室内盘管/蒸发器盘管温度",
		0,
		0,
		"蒸发器盘管温度过高",
		"蒸发器盘管温度过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"CompressorRunningTime",
		"压缩机运行时间",
		"H",
		"压缩机运行时间",
		0,
		0,
		"压缩机运行时间过高",
		"压缩机运行时间过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"UnitRunningTime",
		"机组运行时间",
		"H",
		"机组运行时间",
		0,
		0,
		"机组运行时间过高",
		"机组运行时间过低",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OnOff",
		"空调开/关状态",
		"",
		"空调开/关状态：0-关机，1-开机",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AirConditioningMode",
		"空调运行模式",
		"",
		"空调运行模式：0-自动，1-制冷，2-除湿，3-送风，4-制热",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"IndoorFanStatus",
		"内风机状态",
		"",
		"内风机状态：0-停止，1-低风，2-中风，3-高风",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"FourWayValveStatus",
		"四通阀状态",
		"",
		"四通阀状态：0-停止，1-运行，2-无",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"CompressorStatus",
		"压缩机状态",
		"",
		"压缩机状态：0-停止，1-运行",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OutdoorFanStatus",
		"外风机状态",
		"",
		"外风机状态：0-停止，1-低风，2-中风，3-高风",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"WindyState",
		"摆风状态",
		"",
		"摆风状态：0-停止，1-运行，2-无",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ElectricHeatingState",
		"电加热状态",
		"",
		"电加热状态：0-停止，1-运行，2-无",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"FilterCloggingAlarm",
		"过滤器堵塞报警",
		"",
		"过滤器堵塞报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"CompressorOverloadAlarm",
		"压缩机过载报警",
		"",
		"压缩机过载报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"IndoorFanOverloadAlarm",
		"内风机过载报警",
		"",
		"内风机过载报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"SystemHighPressureAlarm",
		"系统高压报警",
		"",
		"系统高压报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"SystemLowPressureAlarm",
		"系统低压报警",
		"",
		"系统低压报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ExhaustTemperatureAlarm",
		"排气温度报警",
		"",
		"排气温度报警：0-正常，1-高温报警，2-低温报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InternalExternalCommunicationFailure",
		"内外机通讯故障",
		"",
		"内外机通讯故障：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RoomTemperatureSensor",
		"室内环境温度传感器",
		"",
		"室内环境温度传感器：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InnerCoilInletTemperatureSensor",
		"内机盘管进口温度传感器",
		"",
		"内机盘管进口温度传感器：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InternalCoilMiddleTemperatureSensor",
		"内机盘管中间温度传感器",
		"",
		"内机盘管中间温度传感器：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InnerCoilOutletTemperatureSensor",
		"内机盘管出口温度传感器",
		"",
		"内机盘管出口温度传感器：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OutdoorTemperatureSensor",
		"室外环境温度传感器",
		"",
		"室外环境温度传感器：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ExternalCoilTemperatureSensor",
		"外机盘管温度传感器",
		"",
		"外机盘管温度传感器：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ExhaustTemperatureSensor",
		"排气温度传感器",
		"",
		"排气温度传感器：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"PhaseSequenceError",
		"相序错误报警",
		"",
		"相序错误报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"PhaseLossProtection",
		"缺相报警",
		"",
		"缺相报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OutdoorFanProtectionAlarm",
		"室外风机保护报警",
		"",
		"室外风机保护报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"EEPROMFailure",
		"EEPROM故障",
		"",
		"EEPROM故障：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"SmokeAlarm",
		"烟雾告警",
		"",
		"烟雾告警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"IndoorHumiditySensor",
		"室内湿度传感器",
		"",
		"室内湿度传感器：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OutdoorHumiditySensor",
		"室外湿度传感器",
		"",
		"室外湿度传感器：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"SystemException",
		"系统异常",
		"",
		"系统异常：0-正常，1-异常",
		0,
		0,
		"异常",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"LeakageAlarm",
		"水浸告警",
		"",
		"水浸告警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OtherAbnormalAlarms",
		"其它不正常告警",
		"",
		"其它不正常告警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ExternalTheftAlarm",
		"外机被盗告警",
		"",
		"外机被盗告警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"CoolingModeTemperatureSetting",
		"制冷模式温度设定值",
		"",
		"制冷模式温度设定值",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"HeatingModeTemperatureSetting",
		"制热模式温度设定值",
		"",
		"制热模式温度设定值",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	}
};


/**********************************************************************************************************
* 函数名称： static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
* 函数说明： 生成获取传感器数据指令
* 输入参数： 指令索引，传感器地址，变量结构体指针,以及指令缓存区指针,指令长度
* 返回参数： 无
**********************************************************************************************************/
static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
{
	unsigned short i,n,sum;
	switch(index)
	{
		case 0:		//获取模拟量化后的数据 (定点数 )
			*len = sprintf(cmd,"\x7E\x31\x30\x30\x31\x36\x30\x34\x32\x30\x30\x30\x30\xFF\xFF\xFF\xFF\x0D");
			break;
		case 1:		//获取开关状态命令信息
			*len = sprintf(cmd,"\x7E\x31\x30\x30\x31\x36\x30\x34\x33\x30\x30\x30\x30\xFF\xFF\xFF\xFF\x0D");
			break;		
		case 2:		//获取告警状态
			*len = sprintf(cmd,"\x7E\x31\x30\x30\x31\x36\x30\x34\x34\x30\x30\x30\x30\xFF\xFF\xFF\xFF\x0D");
			break;
		case 3:		//获取参数（定点数）
			*len = sprintf(cmd,"\x7E\x31\x30\x30\x31\x36\x30\x34\x37\x30\x30\x30\x30\xFF\xFF\xFF\xFF\x0D");
			break;
		default:
			*len   = 0;
			break;
	}
	if(*len){
		n	= (addr>>4)&0x000F;
		cmd[3] = n>9?(n-10+'A'):n+'0';
		n	= addr&0x000F;
		cmd[4] = n>9?(n-10+'A'):n+'0';			

		for(i=1,sum=0; i<13; i++){
			sum += cmd[i];
		}
		sum = sum%65536;
		sum = ~sum + 1;
		n	= (sum>>12)&0x000F;
		cmd[13] = n>9?(n-10+'A'):n+'0';
		n	= (sum>>8)&0x000F;
		cmd[14] = n>9?(n-10+'A'):n+'0';			
		n	= (sum>>4)&0x000F;
		cmd[15] = n>9?(n-10+'A'):n+'0';	
		n	= sum&0x000F;
		cmd[16] = n>9?(n-10+'A'):n+'0';	
	}
}


/**********************************************************************************************************
* 函数名称： static int parse_fun(short index, int addr, void *data, char *buf, short len)
* 函数说明： 解析传感器响应的数据，并写入数据库
* 输入参数： 解析索引,传感器地址，变量结构体指针，以及响应数据缓存取指针，响应数据长度
* 返回参数： 返回解析结果，返回0成功，返回1失败
**********************************************************************************************************/
static int parse_fun(short index, int addr, void *data, char *buffer, short len)
{
	char *RunMode[6] = {"自动","制冷","除湿","送风","制热","未知"};
	char *FanMode[5] = {"停止","低风","中风","高风","未知"};
	char *Status[3]  = {"停止","运转","无"};	
	union{
		short 			int16;
      	unsigned char  	buf[2];
    }Num;	//数据类型转换
	unsigned short i,j, sum;	
	unsigned char  *buf = (unsigned char*)buffer;
	Data_Struct	*d = (Data_Struct*)data;

	if(buf!=NULL && len>0 && buf[0]==0x7E && buf[len-1]==0x0D)
	{
		//开始校验数据的完整性
		for(i=1,sum=0; i<len-5; i++){
			sum += buf[i];
		}
		sum = sum%65536;
		sum = ~sum + 1;
		//将数据转化为十六进制
		for(i=1,j=1; i<len-1; j++){
			if(buf[i]==0x20) buf[j] = 0;
			else buf[j] = (buf[i] >= '0' && buf[i] <= '9') ? buf[i] - '0' : (buf[i]|32) - 'a' + 10;	
			i++;
			buf[j] <<= 4;
			if(buf[i]==0x20) buf[j]|= 0;
			else buf[j]|= (buf[i] >= '0' && buf[i] <= '9') ? buf[i] - '0' : (buf[i]|32) - 'a' + 10;
			i++;
		}
		Num.buf[1] = buf[j-2];
		Num.buf[0] = buf[j-1];	
		if(sum == Num.int16){
			sum = buf[5]&0x0F;
			sum+= (buf[6]>>4)&0x0F;
			sum+= buf[6]&0x0F;		
			sum = sum%16;
			sum = ~sum + 1;	
			sum = sum&0x0F;
			if(sum != ((buf[5]>>4)&0x0F)){
				return 1;
			}
		}
		else{
			return 1;
		}	
		//校验处理完毕，开始解析数据

		switch(index)
		{
			case 0:
				Num.buf[1] = buf[8];
				Num.buf[0] = buf[9];
				d->APhaseVoltage.value.inum = Num.int16;
				Num.buf[1] = buf[10];
				Num.buf[0] = buf[11];
				d->BPhaseVoltage.value.inum = Num.int16;
				Num.buf[1] = buf[12];
				Num.buf[0] = buf[13];
				d->CPhaseVoltage.value.inum = Num.int16;
				
				Num.buf[1] = buf[14];
				Num.buf[0] = buf[15];
				d->APhaseCurrent.value.inum = Num.int16;
				Num.buf[1] = buf[16];
				Num.buf[0] = buf[17];
				d->BPhaseCurrent.value.inum = Num.int16;
				Num.buf[1] = buf[18];
				Num.buf[0] = buf[19];
				d->CPhaseCurrent.value.inum = Num.int16;

				Num.buf[1] = buf[20];
				Num.buf[0] = buf[21];
				d->DeliveryAirTemperature.value.inum = Num.int16;
				Num.buf[1] = buf[22];
				Num.buf[0] = buf[23];
				d->RoomTemperature.value.inum = Num.int16;

				Num.buf[1] = buf[24];
				Num.buf[0] = buf[25];
				d->DeliveryAirHumidity.value.inum = Num.int16;
				Num.buf[1] = buf[26];
				Num.buf[0] = buf[27];
				d->RoomHumidity.value.inum = Num.int16;

				Num.buf[1] = buf[28];
				Num.buf[0] = buf[29];
				d->CompressorSuctionPressure.value.inum = Num.int16;
				Num.buf[1] = buf[30];
				Num.buf[0] = buf[31];
				d->CompressorExhaustPressure.value.inum = Num.int16;

				Num.buf[1] = buf[33];
				Num.buf[0] = buf[34];
				d->OutdoorTemperature.value.inum = Num.int16;
				Num.buf[1] = buf[35];
				Num.buf[0] = buf[36];
				d->CompressorExhaustTemperature.value.inum = Num.int16;
				Num.buf[1] = buf[37];
				Num.buf[0] = buf[38];
				d->OutdoorHumidity.value.inum = Num.int16;

				Num.buf[1] = buf[39];
				Num.buf[0] = buf[40];
				d->EvaporatorCoilTemperature.value.inum = Num.int16;
				Num.buf[1] = buf[41];
				Num.buf[0] = buf[42];
				d->CompressorRunningTime.value.inum = Num.int16;
				Num.buf[1] = buf[43];
				Num.buf[0] = buf[44];
				d->UnitRunningTime.value.inum = Num.int16;
				break;
			case 1:
				d->OnOff.value.str						  = buf[8]&0x01?"开机":"关机";
				Set_Var_Status(&d->OnOff,					buf[8]&0x01?Normal:Alarm, NULL);
				d->AirConditioningMode.value.str 		  = RunMode[buf[9]<5?buf[9]:5];
				d->IndoorFanStatus.value.str			  = FanMode[buf[10]<4?buf[10]:4];
				Set_Var_Status(&d->IndoorFanStatus,			buf[10]&0x03?ON:OFF, NULL);	
				d->FourWayValveStatus.value.str			  = Status[buf[11]<2?buf[11]:2];
				Set_Var_Status(&d->FourWayValveStatus,		buf[11]==0x01?ON:OFF, NULL);
				d->CompressorStatus.value.str			  = Status[buf[12]?1:0];
				Set_Var_Status(&d->CompressorStatus,		buf[12]?ON:OFF, NULL);
				d->OutdoorFanStatus.value.str			  = FanMode[buf[13]<4?buf[13]:4];
				Set_Var_Status(&d->OutdoorFanStatus,		buf[13]&0x03?ON:OFF, NULL);
				d->WindyState.value.str					  = Status[buf[14]<2?buf[14]:2];
				Set_Var_Status(&d->WindyState,				buf[14]==0x01?ON:OFF, NULL);
				d->ElectricHeatingState.value.str		  = Status[buf[15]<2?buf[15]:2];
				Set_Var_Status(&d->ElectricHeatingState,	buf[15]==0x01?ON:OFF, NULL);
				break;
			case 2:
				if(buf[8]==0x01){
					Set_Var_Status(&d->APhaseVoltage, Alarm, "欠压报警");
				}
				else if(buf[8]==0x02){
					Set_Var_Status(&d->APhaseVoltage, Alarm, "过压报警");
				}
				else if(buf[8]==0x20){
					Set_Var_Status(&d->APhaseVoltage, Alarm, "未检测");
				}				
				else{
					Set_Var_Status(&d->APhaseVoltage, Normal, "正常");					
				}
				
				if(buf[9]==0x01){
					Set_Var_Status(&d->BPhaseVoltage, Alarm, "欠压报警");
				}
				else if(buf[9]==0x02){
					Set_Var_Status(&d->BPhaseVoltage, Alarm, "过压报警");
				}
				else if(buf[9]==0x20){
					Set_Var_Status(&d->BPhaseVoltage, Alarm, "未检测");
				}				
				else{
					Set_Var_Status(&d->BPhaseVoltage, Normal, "正常");					
				}

				if(buf[10]==0x01){
					Set_Var_Status(&d->CPhaseVoltage, Alarm, "欠压报警");
				}
				else if(buf[10]==0x02){
					Set_Var_Status(&d->CPhaseVoltage, Alarm, "过压报警");
				}
				else if(buf[10]==0x20){
					Set_Var_Status(&d->CPhaseVoltage, Alarm, "未检测");
				}				
				else{
					Set_Var_Status(&d->CPhaseVoltage, Normal, "正常");					
				}

				if(buf[11]==0x01){
					Set_Var_Status(&d->APhaseCurrent, Alarm, "欠流报警");
				}
				else if(buf[11]==0x02){
					Set_Var_Status(&d->APhaseCurrent, Alarm, "过流报警");
				}
				else if(buf[11]==0x20){
					Set_Var_Status(&d->APhaseCurrent, Alarm, "未检测");
				}				
				else{
					Set_Var_Status(&d->APhaseCurrent, Normal, "正常");					
				}
				
				if(buf[12]==0x01){
					Set_Var_Status(&d->BPhaseCurrent, Alarm, "欠流报警");
				}
				else if(buf[12]==0x02){
					Set_Var_Status(&d->BPhaseCurrent, Alarm, "过流报警");
				}
				else if(buf[12]==0x20){
					Set_Var_Status(&d->BPhaseCurrent, Alarm, "未检测");
				}				
				else{
					Set_Var_Status(&d->BPhaseCurrent, Normal, "正常");					
				}

				if(buf[13]==0x01){
					Set_Var_Status(&d->CPhaseCurrent, Alarm, "欠流报警");
				}
				else if(buf[13]==0x02){
					Set_Var_Status(&d->CPhaseCurrent, Alarm, "过流报警");
				}
				else if(buf[13]==0x20){
					Set_Var_Status(&d->CPhaseCurrent, Alarm, "未检测");
				}				
				else{
					Set_Var_Status(&d->CPhaseCurrent, Normal, "正常");					
				}

				if(buf[14]==0x01){
					Set_Var_Status(&d->RoomTemperature, Alarm, "低温报警");
				}
				else if(buf[14]==0x02){
					Set_Var_Status(&d->RoomTemperature, Alarm, "高温报警");
				}
				else if(buf[14]==0x20){
					Set_Var_Status(&d->RoomTemperature, Alarm, "未检测");
				}				
				else{
					Set_Var_Status(&d->RoomTemperature, Normal, "正常");					
				}

				if(buf[15]==0x01){
					Set_Var_Status(&d->RoomHumidity, Alarm, "低湿报警");
				}
				else if(buf[15]==0x02){
					Set_Var_Status(&d->RoomHumidity, Alarm, "高湿报警");
				}
				else if(buf[15]==0x20){
					Set_Var_Status(&d->RoomHumidity, Alarm, "未检测");
				}				
				else{
					Set_Var_Status(&d->RoomHumidity, Normal, "正常");					
				}

				d->FilterCloggingAlarm.value.str					 	  = buf[16]==0xF0?"报警":"正常";
				Set_Var_Status(&d->FilterCloggingAlarm,						buf[16]==0xF0?Alarm:Normal, NULL);
				d->CompressorOverloadAlarm.value.str	 				  = buf[17]==0xF0?"报警":"正常";
				Set_Var_Status(&d->CompressorOverloadAlarm,					buf[17]==0xF0?Alarm:Normal, NULL);
				d->IndoorFanOverloadAlarm.value.str	 	 				  = buf[18]==0xF0?"报警":"正常";
				Set_Var_Status(&d->IndoorFanOverloadAlarm,	 				buf[18]==0xF0?Alarm:Normal, NULL);
				d->SystemHighPressureAlarm.value.str	  				  = buf[20]==0xF0?"报警":"正常";
				Set_Var_Status(&d->SystemHighPressureAlarm,	 				buf[20]==0xF0?Alarm:Normal, NULL);				
				d->SystemLowPressureAlarm.value.str	 	 				  = buf[21]==0xF0?"报警":"正常";
				Set_Var_Status(&d->SystemLowPressureAlarm,	 				buf[21]==0xF0?Alarm:Normal, NULL);	

				if(buf[22]==0x01){
					d->ExhaustTemperatureAlarm.value.str	 	  = "高温报警";
					Set_Var_Status(&d->ExhaustTemperatureAlarm, Alarm, NULL);
				}
				else if(buf[22]==0x02){
					d->ExhaustTemperatureAlarm.value.str	 	  = "低温报警";
					Set_Var_Status(&d->ExhaustTemperatureAlarm, Alarm, NULL);
				}
				else if(buf[22]==0x20){
					d->ExhaustTemperatureAlarm.value.str	 	  = "未检测";
					Set_Var_Status(&d->ExhaustTemperatureAlarm, Alarm, NULL);
				}				
				else{
					d->ExhaustTemperatureAlarm.value.str	 	  = "正常";
					Set_Var_Status(&d->ExhaustTemperatureAlarm, Normal, NULL);				
				}					

				d->InternalExternalCommunicationFailure.value.str	 	  = buf[23]==0xF0?"报警":"正常";
				Set_Var_Status(&d->InternalExternalCommunicationFailure,	buf[23]==0xF0?Alarm:Normal, NULL);
				d->RoomTemperatureSensor.value.str	 					  = buf[24]==0xF0?"报警":"正常";
				Set_Var_Status(&d->RoomTemperatureSensor,					buf[24]==0xF0?Alarm:Normal, NULL);
				d->InnerCoilInletTemperatureSensor.value.str	 		  = buf[25]==0xF0?"报警":"正常";
				Set_Var_Status(&d->InnerCoilInletTemperatureSensor,			buf[25]==0xF0?Alarm:Normal, NULL);
				d->InternalCoilMiddleTemperatureSensor.value.str	 	  = buf[26]==0xF0?"报警":"正常";
				Set_Var_Status(&d->InternalCoilMiddleTemperatureSensor,		buf[26]==0xF0?Alarm:Normal, NULL);
				d->InnerCoilOutletTemperatureSensor.value.str	 		  = buf[27]==0xF0?"报警":"正常";
				Set_Var_Status(&d->InnerCoilOutletTemperatureSensor,		buf[27]==0xF0?Alarm:Normal, NULL);
				d->OutdoorTemperatureSensor.value.str	 				  = buf[28]==0xF0?"报警":"正常";
				Set_Var_Status(&d->OutdoorTemperatureSensor,				buf[28]==0xF0?Alarm:Normal, NULL);
				d->ExternalCoilTemperatureSensor.value.str	 			  = buf[30]==0xF0?"报警":"正常";
				Set_Var_Status(&d->ExternalCoilTemperatureSensor,			buf[30]==0xF0?Alarm:Normal, NULL);
				d->ExhaustTemperatureSensor.value.str	 				  = buf[31]==0xF0?"报警":"正常";
				Set_Var_Status(&d->ExhaustTemperatureSensor,				buf[31]==0xF0?Alarm:Normal, NULL);
				d->PhaseSequenceError.value.str	 						  = buf[32]==0xF0?"报警":"正常";
				Set_Var_Status(&d->PhaseSequenceError,						buf[32]==0xF0?Alarm:Normal, NULL);
				d->PhaseLossProtection.value.str	 					  = buf[33]==0xF0?"报警":"正常";
				Set_Var_Status(&d->PhaseLossProtection,						buf[33]==0xF0?Alarm:Normal, NULL);
				d->OutdoorFanProtectionAlarm.value.str				 	  = buf[34]==0xF0?"报警":"正常";
				Set_Var_Status(&d->OutdoorFanProtectionAlarm,				buf[34]==0xF0?Alarm:Normal, NULL);
				d->EEPROMFailure.value.str	 							  = buf[35]==0xF0?"报警":"正常";
				Set_Var_Status(&d->EEPROMFailure,							buf[35]==0xF0?Alarm:Normal, NULL);
				d->SmokeAlarm.value.str	 								  = buf[36]==0xF0?"报警":"正常";
				Set_Var_Status(&d->SmokeAlarm,								buf[36]==0xF0?Alarm:Normal, NULL);
				d->IndoorHumiditySensor.value.str					 	  = buf[37]==0xF0?"报警":"正常";
				Set_Var_Status(&d->IndoorHumiditySensor,					buf[37]==0xF0?Alarm:Normal, NULL);
				d->OutdoorHumiditySensor.value.str	 					  = buf[38]==0xF0?"报警":"正常";
				Set_Var_Status(&d->OutdoorHumiditySensor,					buf[38]==0xF0?Alarm:Normal, NULL);
				d->SystemException.value.str	 						  = buf[39]==0xF0?"报警":"正常";
				Set_Var_Status(&d->SystemException,							buf[39]==0xF0?Alarm:Normal, NULL);
				d->LeakageAlarm.value.str	 							  = buf[40]==0xF0?"报警":"正常";
				Set_Var_Status(&d->LeakageAlarm,							buf[40]==0xF0?Alarm:Normal, NULL);
				d->OtherAbnormalAlarms.value.str	 					  = buf[41]==0xF0?"报警":"正常";
				Set_Var_Status(&d->OtherAbnormalAlarms,						buf[41]==0xF0?Alarm:Normal, NULL);
				d->ExternalTheftAlarm.value.str	 						  = buf[42]==0xF0?"报警":"正常";
				Set_Var_Status(&d->ExternalTheftAlarm,						buf[42]==0xF0?Alarm:Normal, NULL);
				break;				
			case 3:
				Num.buf[1] = buf[19];
				Num.buf[0] = buf[20];
				d->CoolingModeTemperatureSetting.value.inum = Num.int16;
				Num.buf[1] = buf[34];
				Num.buf[0] = buf[35];
				d->HeatingModeTemperatureSetting.value.inum = Num.int16;
				break;				
			default:
				break;
		}
		return 0;
	}
	return 1;
}


/**********************************************************************************************************
* 函数名称： void jmkt_HFIM4_Registration(void)
* 函数说明： 基站空调驱动注册
* 输入参数： 无
* 返回参数： 无
**********************************************************************************************************/
void jmkt_HFIM4_Registration(void)
{
	DeviceDriverRegistration(
		"jmkt",													//设备类型
		"基站空调",												//设备名称（导航栏默认显示名称）
		"海悟",													//设备品牌
		"HFIM4",												//设备型号
		"适用于海悟新型基站专用空调,HFIM4控制器。",				//驱动描述
		var_attr,												//变量属性声明
		sizeof(Data_Struct),									//变量结构体空间大小
		cmd_fun,												//发送指令生成函数
		parse_fun,												//数据解析函数
		1000													//设备响应超时时间
	);
}

